package Lunch;

import static java.lang.System.out;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

//import javax.xml.bind.Marshaller.Listener;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.custom.TableCursor;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

public class Form {

	
	protected Shell shell;
	private static Table table;

	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	static Listener OnOpen = new Listener() {
		
		public void handleEvent(Event e) {
			try {
				BufferedReader myfile = new BufferedReader ( new FileReader("unch.txt"));
			
				String str = new String(myfile.readLine());
			
			 TableItem item = new TableItem(table, SWT.NONE);
			 item.setText(str);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
		}
	};
	
	
	protected void createContents() {
		shell = new Shell();
		shell.setSize(496, 340);
		shell.setText("SWT Application");
		shell.setLayout(new RowLayout(SWT.HORIZONTAL));
		
		Menu menu = new Menu(shell, SWT.BAR);
		shell.setMenuBar(menu);
		
		MenuItem menuItem = new MenuItem(menu, SWT.CASCADE);
		menuItem.setText("Файл");
		
		Menu menu_1 = new Menu(menuItem);
		menuItem.setMenu(menu_1);
		
		MenuItem menuItem_1 = new MenuItem(menu_1, SWT.NONE);
		menuItem_1.setText("Открыть");
		menuItem_1.addListener(SWT.NONE, OnOpen);
		
		
		
		MenuItem menuItem_2 = new MenuItem(menu_1, SWT.NONE);
		menuItem_2.setText("Выход");
		
		table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
		table.setLayoutData(new RowData(254, 167));
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn.setWidth(100);
		tblclmnNewColumn.setText("Блюдо");
		
		TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_1.setWidth(70);
		tblclmnNewColumn_1.setText("Вес");
		
		TableColumn tableColumn = new TableColumn(table, SWT.NONE);
		tableColumn.setWidth(70);
		tableColumn.setText("Цена");
		
		Label lblNewLabel = new Label(shell, SWT.NONE);
		lblNewLabel.setText("Категория");
		
		CCombo combo = new CCombo(shell, SWT.BORDER);
		combo.setItems(new String[] {"Первое", "Второе", "Гарнир"});
		combo.setLayoutData(new RowData(125, SWT.DEFAULT));

	}
}
